package com.woniuxy.his.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.his.entity.Guahao;
import com.woniuxy.his.entity.Patient;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.his.vo.PatientByCheckeIdVo;
import com.woniuxy.his.vo.PatientByprescriptionIdVo;
import com.woniuxy.his.vo.PayOfPrescriptionVo;
import org.apache.ibatis.annotations.Param;
import com.woniuxy.his.vo.GuaHaoVo;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 病人表 Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2021-08-24
 */
@Repository
public interface PatientMapper extends BaseMapper<Patient> {

    @Select("select * from his_patient where patientName like concat('%',#{patientName},'%')")
    IPage<Patient> findByPage(IPage<Patient> page, String name);

    @Select("SELECT hp.prescription_id,hc.patient_name from his_prescription hp ,his_case hc where ispaid='yes' and is_give_medicine=#{isGiveMedicine} and hp.case_id=hc.case_id and hp.rwa_add_time between #{startTime} and #{stopTime}")
    IPage<PayOfPrescriptionVo> findPatientByPageAndStatu(IPage<Patient> page, @Param("isGiveMedicine") String isGiveMedicine, @Param("startTime") Date startTime, @Param("stopTime") Date stopTime);

    //根据处方id获取病人信息
    @Select("select hp.prescription_id,hpt.patient_name,hpt.patient_gender, hp.rwa_add_time from his_prescription hp,his_case hc,his_patient hpt where prescription_id = #{prescriptionId} and hp.case_id=hc.case_id and hc.patient_id=hpt.patient_id")
    PatientByprescriptionIdVo getMsgOfOne(Integer prescriptionId);

    //根据项目id获取病人信息
    @Select("select hck.check_id,hpt.patient_name,hpt.patient_gender, hck.rwa_add_time from his_check hck,his_case hc,his_patient hpt where hck.check_id = #{checkId} and hck.case_id=hc.case_id and hc.patient_id=hpt.patient_id")
    PatientByCheckeIdVo getMsgOfOneByCheckId(Integer checkId);
    //项目划价中根据挂号查询病人信息
    @Select("select hg.guahao_update_time,hg.gua_id,hg.status,hp.patient_name,hp.patient_age,hp.patient_gender,hp.patient_tel,hp.patient_id_card,hc.symptom,hc.dia_result,hd.doctor_name,hde.dep_name from his_guahao hg,his_patient hp,his_case hc,his_doctor hd,his_department hde where hg.patient_id=hp.patient_id and hg.dep_id=hde.dep_id and hg.doctor_id=hd.doctor_id and hp.patient_id=hc.patient_id and hg.gua_id=#{input}")
    public GuaHaoVo searchPatientByProject(Integer input);
}
